import { InputQuestion, QuestionBase, TextQuestion, TimeQuestion } from '@/components/public-template';
import { TextTable } from '@/components/public-template';
import { TableBase } from '@/components/public-template';
import { regExp } from '@/utils/regExp';
import { Api as ApiFile } from '@/config/api/fileInfo';

class HomeService {
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'name',
        label: '名称',
        value: null
      })
    ];
    return questions;
  }
  getIcons() {
    const icons: TableBase<any>[] = [
      new TextTable({
        key: 'local',
        type: 'primary',
        value: '设置',
        class: 'PlusOutlined',
        state: {
          name: 'setUp'
        }
        // params: [{ fileType: 'categorize' }]
        // state: {
        //   form: this.getSetQuestions(),
        //   config: {
        //     title: '设置',
        //     width: '420px',
        //     type: 'layer',
        //     grid: 24,
        //     labelCol: 24,
        //     wrapperCol: 24,
        //     layout: 'vertical',
        //     addUrl: ApiFile.dirConfigSave
        //   }
        // }
      })
    ];
    return icons;
  }
  getTables(level) {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'key',
        value: null,
        type: 'slot',
        columns: { width: 60 },
        state: {
          slotName: 'fileImg'
        }
      }),
      new TextTable({
        key: 'name',
        value: '文件名称',
        type: 'slot',
        state: {
          slotName: 'fileName'
        },
        columns: {
          width: 350,
          sorter: (a, b) => {
            return a.name.localeCompare(b.name);
          }
        }
      }),
      new TextTable({
        key: 'size',
        value: '大小',
        type: 'slot',
        state: {
          slotName: 'size'
        },
        columns: {
          sorter: (a, b) => {
            return b.size - a.size;
          }
        }
      }),
      new TextTable({
        key: 'maxSize',
        value: '容量上限',
        type: 'slot',
        state: {
          slotName: 'maxSize'
        },
        columns: {
          sorter: (a, b) => {
            return b.maxSize - a.maxSize;
          }
        }
      }),
      new TextTable({
        key: 'actions',
        value: '操作',
        columns: { width: 150 },
        type: 'slot',
        state: {
          slotName: 'setCapacity'
        }
        // handle: [
        //   {
        //     type: 'layerFrom',
        //     text: '设置',
        //     class: 'text-primary',
        //     params: [{ fileType: 'categorize' }],
        //     state: {
        //       form: this.getSetQuestions(),
        //       config: {
        //         title: '设置',
        //         width: '390px',
        //         type: 'layer',
        //         grid: 24,
        //         labelCol: 24,
        //         wrapperCol: 24,
        //         layout: 'vertical',
        //         addUrl: ApiFile.dirConfigSave
        //       }
        //     }
        //   }
        // ]
      })
    ];
    return tables;
  }
  getSetQuestions(maxSize, categorize, folderId, unit) {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'maxSize',
        label: '容量上限',
        reg: regExp.maxdigital6,
        prompt: '容量上限不可为空，至多允许输入6位数正整数',
        type: 'number',
        value: maxSize,
        state: {
          extendParams: {
            unit: unit,
            categorize: categorize,
            folderId: folderId
          },
          addonAfter: {
            key: 'unit',
            tagType: 'select',
            options: [
              { label: 'MB', value: 'MB' },
              { label: 'GB', value: 'GB' },
              { label: 'TB', value: 'TB' }
            ]
          }
        }
      })
    ];
    return questions;
  }
  getAllQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'allMaxSize',
        label: '容量上限',
        reg: regExp.maxdigital6,
        prompt: '容量上限不可为空，至多允许输入6位数正整数',
        type: 'number',
        value: null,
        state: {
          extendParams: {
            unit: 'GB'
          },
          addonAfter: {
            key: 'unit',
            tagType: 'select',
            options: [
              { label: 'MB', value: 'MB' },
              { label: 'GB', value: 'GB' },
              { label: 'TB', value: 'TB' }
            ]
          }
        }
      })
    ];
    return questions;
  }
}

export default new HomeService();
